/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.view.backingbean;

import br.com.model.core.ClienteDao;
import br.com.model.entity.Cliente;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.SessionScoped;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

/**
 *
 * @author Aluno
 */
@SessionScoped
@ManagedBean(name = "backingCliente")
public class BackingCliente {

    private Cliente c1;
    private List<Cliente> clientes;
    private ClienteDao cD1;
    private DataModel listaClientes;
    private boolean logado;
    private boolean admin;

    public BackingCliente() {
        this.cD1 = new ClienteDao();
        this.clientes = cD1.list(Cliente.class);
        this.logado = false;
        this.admin = false;
    }

    public DataModel getListarCliente() {
        clientes = cD1.list(Cliente.class);
        listaClientes = new ListDataModel(clientes);
        return listaClientes;
    }

    public Cliente getC1() {
        return c1;
    }

    public void setC1(Cliente c1) {
        this.c1 = c1;
    }

    public List<Cliente> getClientes() {
        return clientes;
    }

    public String preparaAdicionarCliente() {
        System.out.println("AQUI Prepara CLIENTE......");
        this.c1 = new Cliente();
        return Outcomes.CADASTRAR_USER;
    }

    public String preparaAlteraCliente() {
        this.c1 = (Cliente) (listaClientes.getRowData());
        return Outcomes.ALTERACLIENTE;
    }

    public String addCliente() {
        System.out.println("AQUI ADD CLIENTE......");
        c1.setRole("CLI");
        cD1.save(c1);
        return Outcomes.INDEX;
    }

    public String deleteCliente() {
        Cliente cTemp = (Cliente) (listaClientes.getRowData());

        cD1.delete(cTemp);
        return Outcomes.MENU;
    }

    public String alteraCliente() {
        cD1.update(c1);
        return Outcomes.MENU;
    }

    public boolean isLogado() {
        return logado;
    }

    public void setLogado(boolean logado) {
        this.logado = logado;
    }

    public void test() {
        System.out.println("vlkjb");
        System.out.println("asa");
        System.out.println("asdacd");
        System.out.println("cx");
        System.out.println("xczcz");

    }

    public String logar() {
       /* for (Cliente cliente : clientes) {
            if (cliente.getLogin().equals(c1.getLogin())) {
                if (cliente.getPassword().equals(c1.getPassword())) {
                    logado = true;
                    if(c1.getRole)
                }
            }
        }*/
        if("admin".equals(c1.getLogin()) && "admin".equals(c1.getPassword())){
        logado = true;
        admin = true;
        }
return Outcomes.MAIN;
    }

    public boolean isAdmin() {
        return admin;
    }

    public void setAdmin(boolean admin) {
        this.admin = admin;
    }
    
}
